<!DOCTYPE html>
<html lang="zh">

<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdn.staticfile.net/vue/2.7.8/vue.js"></script>
    <link href="../css/style.css" rel="stylesheet">
    <style>
        .goodName {
            color: red;
        }
    </style>
</head>

<body>
<div id="app">
    <!--    <label>-->
    <!--        <input v-model.lazy="name" placeholder="输入年龄">-->
    <!--    </label>-->

    <!--    <label>-->
    <!--        <input v-model.number="age" type="number">-->
    <!--    </label>-->

    <!--    <label>-->
    <!--        <input v-model.trim="content" type="text" placeholder="输入内容">-->
    <!--    </label>-->

    <br>

    <!--  用户注册表单  -->

    <h1>用户注册</h1>
    <div>
        <label for="userName">姓名</label>
        <input type="text" id="userName" v-model.lazy="userName" v-on:change="checkUserName">
        <span v-bind:class="{goodName: checkUsernameOK}" v-if="checkUsernameOK">可以注册</span>
    </div>

    <div>
        <label for="age"> 年龄 </label>
        <input id="age" v-model.number="age" type="number">

    </div>

    <div>
        <label for="content"> 内容 </label>
        <textarea id="content" cols="55" rows="8" v-model.trim="content"></textarea>
    </div>

    <h4>信息区</h4>
    <p>userName：{{userName}}</p>
    <p>age：{{age}}</p>
    <p>content：{{content}}</p>
</div>
<script>
    const vm = new Vue({
        el: '#app',
        data: {
            userName: '',
            age: 0,
            content: '',
            checkUsernameOK: false
        },
        methods: {
            checkUserName: function () {
                if (this.userName.length > 0) {
                    this.checkUsernameOK = true;
                    return;
                }
                this.checkUsernameOK = false;
            }
        }
    });
</script>
</body>
</html>